package permissions

import (
	"context"
	"goAdminV1/internal/model"
	"goAdminV1/utility"

	"goAdminV1/api/permissions/v1"
)

func (c *ControllerV1) JobDetail(ctx context.Context, req *v1.JobDetailReq) (res *v1.JobDetailRes, err error) {
	// 调用 model 层方法查询岗位详情
	jobDetail, err := model.GetJobById(ctx, req.Id)
	if err != nil {
		return nil, utility.Error(utility.CodeOperation, err)
	}
	// 将 JobWithCreator 转换为 JobDetailRes
	res = &v1.JobDetailRes{
		JobName:     jobDetail.JobName,
		Coding:      jobDetail.Coding,
		Description: jobDetail.Description,
		Sort:        jobDetail.Sort,
		Status:      jobDetail.Status,
		CreatedAt:   utility.TimeToDate(int64(jobDetail.CreatedAt), ""),
		UpdatedAt:   utility.TimeToDate(int64(jobDetail.UpdatedAt), ""),
		Creator:     jobDetail.Creator,
	}
	return res, nil
}
